﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;


namespace AIPASoft.CommonLibrary.WPF.KeyboardHook
{
    public class CheckBoxKeyBoardNavigation : KeyboardFocusNavigationBase
    {

        public override void Register()
        {
            Register<CheckBox>();
        }


        public override void UnRegister()
        {
            //TODO : Analyze and give proper solution
            throw new NotImplementedException();
        }

        protected override void KeyDownEvent(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }

            var checkBox = sender as CheckBox;
            if (checkBox == null)
            {
                return;
            }

            MoveToNextUIElement(e);
            //Sucessfully moved on and marked key as handled.
            //Toggle check box since the key was handled and
            //the checkbox will never receive it.
            if (e.Handled)
            {
                checkBox.IsChecked = !checkBox.IsChecked;
            }
        }
    }
}
